package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.base.domain.IntegralStore;
import cn.wolfcode.trip.base.domain.User;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.query.StrategyCommentQueryObject;
import cn.wolfcode.trip.base.query.TravelQueryObject;
import cn.wolfcode.trip.base.service.*;
import cn.wolfcode.trip.base.util.JSONResult;
import com.github.pagehelper.PageInfo;
import com.sun.corba.se.spi.ior.ObjectKey;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/integralStores")
public class IntegralStoreController {

    @Autowired
    private IIntegralStoreService integralStoreService;
    @Autowired
    private ISignService iSignService;

    //查询所有商品
    @GetMapping
    public Object selectAll(QueryObject qo){
        PageInfo<IntegralStore> pageInfo = integralStoreService.query(qo);
        System.out.println(pageInfo);
        return pageInfo;
    }
    //查询单个数据的信息
    @GetMapping("{id}")
    public IntegralStore list(@PathVariable Long id){
        return integralStoreService.selectOne(id);
    }

    //点击购买
    @PostMapping
    public JSONResult buy(Long userId,Long productId,Long productIntegral){
        System.out.println(userId+"/"+productId+"/"+productIntegral);
        //保存中间表用于查询用户买了些什么
        integralStoreService.insertRelation(userId,productId);
        //购买成功后扣除对应的积分
        iSignService.deletePoint(userId,productIntegral);
        return new JSONResult();
    }

}
